package com.csmz.mybookreader.UI;


import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.csmz.mybookreader.DBSQLite.DbMySQLite;
import com.csmz.mybookreader.R;
import com.csmz.mybookreader.UserBean.UserInfo;
import com.csmz.mybookreader.Utils.AnalysisUtils;

public class MyMessageActivity extends AppCompatActivity {
    private TextView tv_name,tv_sex,tv_age,tv_city;
    private TextView tv_back,msg_name;
    private final static String TAG="MyMessageActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_my_message);
        //设置此界面为竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        init();
    }

    /**
     * 获取界面控件
     */
    private void init() {
        tv_back=findViewById(R.id.tv_back);
        msg_name=findViewById(R.id.msg_tv_user_name);
        tv_name=findViewById(R.id.main_tv_name);
        tv_sex=findViewById(R.id.main_tv_sex);
        tv_age=findViewById(R.id.main_tv_age);
        tv_city=findViewById(R.id.main_tv_city);
        setText();
        tv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    /**
     * 设置文本内容
     */
    private void setText() {
        //从SharedPreferences获取用户名
        String userName = AnalysisUtils.readLoginUserName(MyMessageActivity.this);
        tv_name.setText(userName);
        //根据用户名查询数据
        DbMySQLite dbMySQLite=new DbMySQLite(MyMessageActivity.this);
        UserInfo userInfo=dbMySQLite.findUserInfo(userName);
        msg_name.setText(userName);
        if (TextUtils.isEmpty(userInfo.getGender())){
            tv_age.setText("空");
        }else {
            tv_sex.setText(userInfo.getGender());
        }
        if (TextUtils.isEmpty(userInfo.getYear())){
            tv_age.setText("空");
        }else {
            tv_age.setText(userInfo.getYear());
        }
        if (TextUtils.isEmpty(userInfo.getCity())){
            tv_age.setText("空");
        }else {
            tv_city.setText(userInfo.getCity());
        }
        //1Log.d(TAG, "setText: "+userInfo.getCity());

    }

}
